<?php

namespace app\admin\model;

use think\facade\Config;
use think\facade\Session;
use think\Model;
use think\model\concern\SoftDelete;

class Role extends Model
{
    use SoftDelete;
    protected $table = 'role';
    protected $insert = [
        'create_user',
        'update_user',
    ];
    protected $update = [
        'update_user',
    ];

    public function setCreateUserAttr()
    {
        return Session::get(Config::get('user_session_key'))['id'];
    }

    public function setUpdateUserAttr()
    {
        return Session::get(Config::get('user_session_key'))['id'];
    }

    /**
     * 角色所有的权限
     * @return \think\model\relation\BelongsToMany
     */
    public function permissions()
    {
        return $this->belongsToMany('app\admin\model\Permission','role_permission','permission_id','role_id');
    }

}
